package com.itsc.dao;

import java.util.List;

import org.hibernate.Query;

import com.itsc.entities.ProductType;

@SuppressWarnings("unchecked")
public class ProductTypeDao extends BaseDao<ProductType>{

	public List<ProductType> selectByNull(String hql){
		
		Query query = getSession().createQuery(hql);
		List<ProductType> list = query.list();
		return list;
	}
	
	public Boolean selectByString(String hql,String name){
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		List<ProductType> list = query.list();
		if(list.size()==0){
			return true;
		}else{
			return false;
		}
	}
	
	public Integer selectIdByString(String hql, String name){
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		List<ProductType> list = query.list();
		Integer id = list.get(0).getPt_id();	
		return id;
	}
	
	public ProductType selectByIntId(String hql,Integer id){
		Query query = getSession().createQuery(hql);
		query.setInteger(0, id);
		List<ProductType> list = query.list();
		if(list.size()!=0){
			ProductType pt = list.get(0);
			return pt;
		}else{
			return null;
		}
	}
	
	public List<ProductType> ptList(String hql, Integer pt_id) {
		Query query = getSession().createQuery(hql);
		query.setInteger(0, pt_id);
		List<ProductType> list = query.list();
		if(list.size()!=0){
			return list;
		}else{
			return null;
		}
	}
}
